package com.iplay.dao.notification;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;

import com.iplay.entity.notification.NotificationDO;

public interface NotificationDAO extends PagingAndSortingRepository<NotificationDO, Integer> {
	
	Page<NotificationDO> findByStatus(boolean status, Pageable pageable);
	
	@Transactional
	@Modifying
	@Query("update NotificationDO h set h.status = ?2 where h.id = ?1")
	void updateRead(int id, boolean read);
	
	@Query("SELECT COUNT(*) FROM NotificationDO h where h.status = ?1")
	int countRead(boolean read);
}
